package Recursion;

import Stack.ArrayStack;

/**
 * @author yyq
 * @create 2021-10-12 20:44
 */
public class MigongRec {
    static int[][] mg = {                           //迷宫地图,1代表墙壁，0代表通路
            {1,1,1,1,1,1,1,1,1,1},
            {1,0,0,1,0,0,0,1,0,1},
            {1,0,0,1,0,0,0,1,0,1},
            {1,0,0,0,0,1,1,0,0,1},
            {1,0,1,1,1,0,0,0,0,1},
            {1,0,0,0,1,0,0,0,0,1},
            {1,0,1,0,0,0,1,0,0,1},
            {1,0,1,1,1,0,1,1,0,1},
            {1,1,0,0,0,0,0,0,0,1},
            {1,1,1,1,1,1,1,1,1,1}
    };
    public static Boolean findWay(int[][] map,int i,int j){
        if(map[8][8]==2){
            return true;
        }else {
            if(map[i][j]==0){
                map[i][j]=2;
            }
            //下
            else if(findWay(map,i+1,j)){
                return true;
            }
            //右
            else if(findWay(map,i,j+1)){
                return true;
            }
            //左
            else if(findWay(map,i,j-1)){
                return true;
            }
            //上
            else if(findWay(map,i-1,j)){
                return true;
            }

            else {

                map[i][j]=3;
                return false;
            }

        }
        return false;

    }

    public static void main(String[] args) {
        for (int i = 0; i < MIgong.mg.length; i++) {
            for (int i1 = 0; i1 < mg[0].length; i1++) {
                System.out.print(mg[i][i1]+" ");
            }
            System.out.println();
        }
        findWay(MigongRec.mg,1,1);
        System.out.println("****************");
        for (int i = 0; i < MIgong.mg.length; i++) {
            for (int i1 = 0; i1 < mg[0].length; i1++) {
                System.out.print(mg[i][i1]+" ");
            }
            System.out.println();
        }
    }

}
